#include <interfacelib/window/scroll.h>
#include <utillib/string/string.h>

using namespace interfacelib::Window;

ScrollWithString::ScrollWithString() 
{
}

ScrollWithString::~ScrollWithString()
{
}

bool ScrollWithString::drawElement( int x, int y, utillib::string::String *object )
{
	const char *sz = ( ( utillib::string::String *)object )->getBuffer();
	drawText( x, y, sz );
	return ( true );
}

void ScrollWithString::removeString( const char *string )
{
	{
		listElement::iterator iter_end( m_listElement.end() );
		for ( listElement::iterator iter = m_listElement.begin(); iter != iter_end ; ++iter )
		{
			utillib::string::String *scrollString = ( *iter );
			if ( !strcmp( scrollString->getBuffer(), string ) )
			{
				removeObject( scrollString );
				m_listElement.erase( iter ) ; 
				return;
			}
		}
	}
}

void ScrollWithString::addString( const char *string )
{
	if ( isExist( string ) ) return;

	utillib::string::String *insertString = new utillib::string::String;
	*insertString = string;

	addElement( insertString );
}

bool ScrollWithString::isExist( const char *findObject )
{
	if ( !findObject ) return ( false );
	{
		listElement::const_iterator iter_end( m_listElement.end() );
		for ( listElement::const_iterator iter = m_listElement.begin(); iter != iter_end ; ++iter )
		{
			utillib::string::String *object = ( *iter );
			if ( object->compare( findObject ) ) return ( true );
		}
		return ( false );
	}
}			
